Description:
The switch statement is similar to a series of
if statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.
Concept does not support labels and goto. The switch implementation is a little different from the C standard switch, mainly because instead of constant values, you can have full expressions (any expression).
Example
switch (i) {
case 0:
echo "i is zero";
break; // notice the break statement to prevent execution of the next case label
case 1:
case 2:
echo "i is one or two"; // if i is 1 or 2 this code will be executed
break;
case 2+1: // notice an expression here
echo "i is 2 + 1";
break;
case "test": // a string expression
echo "i is 'test'"; // notice that is no break here
case "somedata"+2: // if i is "test" this statement will be executed too
echo "i is a string";
break;
default: // if no value is found this will be executed.
echo "i has another value"; // the default case is optional
}